package com.itheima.controller;

import com.itheima.common.Code;
import com.itheima.common.MessageConstant;
import com.itheima.common.Result;
import com.itheima.entity.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: fan
 * @Desc: 套餐模块
 * @Date: 2022/6/7 15:21
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 功能描述: 套餐数据回显
     *
     * @return : com.itheima.common.Result
     */
    @GetMapping("/list")
    public Result list(@RequestParam("categoryId") Long categoryId,
                       @RequestParam("status") Integer status) {
        List<Setmeal> list = setmealService.list(categoryId, status);
        if (list == null) {
            return new Result(Code.ERROR, MessageConstant.SETMEAL_GET_ERROR);
        }

        return new Result(Code.OK, MessageConstant.SETMEAL_GET_SUCCESS, list);
    }
}
